load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin


fuc    = addfile("/mypath/ecmwf/ua250hpa_19792004djf.nc","r")
fuw    = addfile("/mypath/ecmwf/ua250hpa_20092019djf.nc", "r")

fvc    = addfile("/ecmwf/va250hpa_19792004djf.nc","r")
fvw    = addfile("/ecmwf/va250hpa_20092019djf.nc", "r")

;*******************************************;
;Read in and setup the variables
;*******************************************
lat=fuc->latitude(::-1)
lon=fuc->longitude
time=fuc ->time


nlat  = dimsizes(lat)
nlon  = dimsizes(lon)
ntime= dimsizes(time)

uc=fuc->ua250(:,::-1,:)
uw=fuw->ua250(:,::-1,:)


vc=fvc->va250(:,::-1,:)
vw=fvw->va250(:,::-1,:)

sfct=uv2sfvpF(uc,vc)
sfwt=uv2sfvpF(uw,vw)

sfc=sfct(0,:,:,:)
sfw=sfwt(0,:,:,:)

sfc!0 = "time"
sfc!1 = "lat"
sfc!2 = "lon"
sfw!0 = "time"
sfw!1 = "lat"
sfw!2 = "lon"

sfc&lat = lat
sfc&lon = lon
sfw&lat = lat
sfw&lon = lon


;************************************************
; average over the simulations/years
;************************************************
;exit
finfo_uws=sfc(0,:,:)
finfo_uws=dim_avg(sfw(lat|:,lon|:,time|:))

finfo_ucs=sfw(0,:,:)
finfo_ucs=dim_avg(sfc(lat|:,lon|:,time|:))

;************************
; calculate the anomaly:
;************************

  speed_ano=finfo_uws
  speed_ano=(finfo_uws-finfo_ucs)/100000.

;********************************************
;            Making Plots
;********************************************
wks = gsn_open_wks("pdf","lowMctrl1_20092019min19792004_streamfunction250hpa")

gsn_define_colormap(wks,"BlueDarkOrange18")
plot = new(1,graphic)                          ; create a plot array

  res          = True
  res@gsnDraw  = False                          ; don't draw
  res@gsnFrame = False                          ; don't advance frame, these 2
  res@cnInfoLabelOn = False                     ; turn off cn info label

  res@cnLinesOn           = True
  res@cnFillOn            = True          ; turn on color
  res@lbLabelBarOn        = True 

  res@cnLevelSelectionMode =  "ExplicitLevels"

  res@cnLineLabelsOn=False
  res@mpCenterLonF     = 290.
  res@gsnPolar   = "NH"
  res@mpMinLatF            = 0.

 res@cnMonoLineColor = True
 res@cnMonoLineThickness= True
 res@cnLineThicknessF = 2.
 res@cnLineColorF= "black"

 res@gsnContourNegLineDashPattern=1
 res@gsnContourZeroLineThicknessF=3

 res@gsnCenterStringFontHeightF = 0.03
 res@gsnRightStringFontHeightF = 0.03
 res@gsnLeftStringFontHeightF = 0.03

 res@mpGeophysicalLineThicknessF = 2.
 res@gsnLeftString = ""
 res@gsnCenterString = ""
 res@gsnRightString = ""

 res@cnFillColors = (/2,3,4,5,8,10,0,0,13,14,15,16,17,18/)
 res@cnLevels =(/-30,-25,-20.,-15.,-10.,-5.,0, 5., 10.,15.,20.,25.,30./)
 plot(0) = gsn_csm_contour_map(wks,speed_ano(:,:),res)

 ;________________________
; creating the panel:
;________________________
 resP            = True

resP@gsnPanelLabelBar    = False;True                ; add common colorbar
resP@lbLabelFontHeightF  = 0.007               ; make labels smaller

resP@gsnPanelBottom   = 0.05                   ; add space at bottom
;resP@gsnPanelFigureStrings= (/"a)","b)","c)"/) ; add strings to panel
res@txFontHeightF     = .24


resP@gsnMaximize    = True                ; maximize plot
gsn_panel(wks,plot,(/1,1/),resP)

end
 
